'use strict';
Object.defineProperties(exports, {
  __esModule: { value: !0 },
  [Symbol.toStringTag]: { value: 'Module' },
});
const k = require('./rng.cjs'),
  y = require('./stringify.cjs');
let q,
  i,
  a = 0,
  _ = 0;
function S(e, x, g) {
  let n = (x && g) || 0;
  const l = x || new Array(16);
  e = e || {};
  let u = e.node || q,
    c = e.clockseq !== void 0 ? e.clockseq : i;
  if (u == null || c == null) {
    const f = e.random || (e.rng || k.default)();
    u == null && (u = q = [f[0] | 1, f[1], f[2], f[3], f[4], f[5]]),
      c == null && (c = i = ((f[6] << 8) | f[7]) & 16383);
  }
  let t = e.msecs !== void 0 ? e.msecs : Date.now(),
    s = e.nsecs !== void 0 ? e.nsecs : _ + 1;
  const m = t - a + (s - _) / 1e4;
  if (
    (m < 0 && e.clockseq === void 0 && (c = (c + 1) & 16383),
    (m < 0 || t > a) && e.nsecs === void 0 && (s = 0),
    s >= 1e4)
  )
    throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
  (a = t), (_ = s), (i = c), (t += 122192928e5);
  const d = ((t & 268435455) * 1e4 + s) % 4294967296;
  (l[n++] = (d >>> 24) & 255),
    (l[n++] = (d >>> 16) & 255),
    (l[n++] = (d >>> 8) & 255),
    (l[n++] = d & 255);
  const r = ((t / 4294967296) * 1e4) & 268435455;
  (l[n++] = (r >>> 8) & 255),
    (l[n++] = r & 255),
    (l[n++] = ((r >>> 24) & 15) | 16),
    (l[n++] = (r >>> 16) & 255),
    (l[n++] = (c >>> 8) | 128),
    (l[n++] = c & 255);
  for (let f = 0; f < 6; ++f) l[n + f] = u[f];
  return x || y.unsafeStringify(l);
}
exports.default = S;
